﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using ForkCarRelationManager.db;

namespace ForkCarRelationManager.Business
{
       
    class ScompanyBI
    {
        DataTable scompanyTable;
        DataPaging ScompanyPage;
        DataSet ScompanyDataSet;
        int pagecount = 10000;
        dbOperate dbo = new dbOperate();
        public DataPaging GetScompanypage()
        {
            ScompanyPage = new DataPaging("ScompanyInfor s", pagecount, "(select sum(1) from ScompanyInfor where ID<=s.ID ) as 序号,s.ScompanyName,s.ScompanyLoca,s.ManagerName,s.ManagerPhone,s.ID as ID", "1=1","s");
            return ScompanyPage;
        }
        /*
       * 获取公司数据
       * */
        public DataTable Getscompanyinfor(int scompanyid)
        {
            String sqlCompany = "select ScompanyInfor.ScompanyName,ScompanyInfor.ScompanyLoca,ScompanyInfor.ManagerName,ScompanyInfor.ManagerPhone,ScompanyInfor.Scompanysummary from ScompanyInfor where ID=" + scompanyid;
            DataTable companyTable = dbo.GetDate(sqlCompany);
            if (companyTable == null)
            {
                companyTable = new DataTable();
                companyTable.Columns.Add("ID");
                companyTable.Columns.Add("ScompanyName");
                companyTable.Rows.Add("", "");
            }
            return companyTable;
        }
        /*
      * 更改公司数据
      * */
        public bool Updatescompany(string ScompanyName, string ScompanyLoca, string ManagerPhone, string ManagerName, string Scompanysummary,int companyid)
        {
            return dbo.UpdateAndInsert("update ScompanyInfor set ScompanyName='" + ScompanyName + "',ScompanyLoca='" + ScompanyLoca + "',ManagerName='" + ManagerName + "',ManagerPhone='" + ManagerPhone + "',Scompanysummary='" + Scompanysummary + "' where ID=" + companyid);
        }
        /*
    * 添加公司数据
    * */
        public bool Addscompany(string ScompanyName, string ScompanyLoca, string ManagerPhone, string ManagerName, string Scompanysummary)
        {
            bool ifaddsucs = dbo.UpdateAndInsert("insert into ScompanyInfor (ScompanyName,ScompanyLoca,ManagerName,ManagerPhone,Scompanysummary) values ('" + ScompanyName + "','" + ScompanyLoca + "','" + ManagerName + "','" + ManagerPhone + "','" + Scompanysummary + "')");
            return ifaddsucs;
        }

        //获取公司所有数据
        public DataTable allCompany()
        {
            String sql = "select * from ScompanyInfor";
           return dbo.GetDate(sql);
        }

    }
}
